package com.goku.framework.ui.adminlte;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import freemarker.core.DirectiveCallPlace;
import freemarker.core.Environment;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateNodeModel;

public class TableTag extends UiTag {

	private static Logger logger = LoggerFactory.getLogger(TableTag.class);

	@Override
	public String getHTML(Environment env, Map params,
			TemplateDirectiveBody body) {
	 
		 DirectiveCallPlace  nodeModel=env.getCurrentDirectiveCallPlace();
	       
		String style="";
		String width = null;
		if (params.containsKey("width")) {
			width = ((SimpleScalar) params.get("width")).getAsString();
            style+="width:"+width+";";
		}
		 
		StringBuilder sb = new StringBuilder();
		sb.append("<div class=\"box-body\" style=\""+style+"\"");
		
		sb.append(">\r\n");
		sb.append(" <table class=\"table table-bordered\">\r\n");
		sb.append("		 <tr>");
		sb.append("         <th style=\"width: 10px\">#</th>\r\n");
		sb.append("         <th>Task</th>\r\n");
		sb.append("        <th>Progress</th>\r\n");
		sb.append("       <th style=\"width: 40px\">Label</th>\r\n");
		sb.append("      </tr>\r\n");
		sb.append("</table>\r\n");
		sb.append("</div>\r\n");
		return sb.toString();

	}

	@Override
	public void render(Environment env, Map params, TemplateDirectiveBody body)
			throws IOException, TemplateException {
		logger.debug("body:" + body);
	 
		Writer w = env.getOut();

		w.write(getHTML(env, params, body));

		renderBody(env, body);
	}

}
